#ifndef __ALT_LEGACY_IRQ_H__
#define __ALT_LEGACY_IRQ_H__

/******************************************************************************
*                                                                             *
* License Agreement                                                           *
*                                                                             *
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA.           *
* All rights reserved.                                                        *
*                                                                             *
* Permission is hereby granted, free of charge, to any person obtaining a     *
* copy of this software and associated documentation files (the "Software"),  *
* to deal in the Software without restriction, including without limitation   *
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
* and/or sell copies of the Software, and to permit persons to whom the       *
* Software is furnished to do so, subject to the following conditions:        *
*                                                                             *
* The above copyright notice and this permission notice shall be included in  *
* all copies or substantial portions of the Software.                         *
*                                                                             *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
* DEALINGS IN THE SOFTWARE.                                                   *
*                                                                             *
* This agreement shall be governed in all respects by the laws of the State   *
* of California and by the laws of the United States of America.              *
*                                                                             *
******************************************************************************/

/*
 * This file provides prototypes and inline implementations of certain routines
 * used by the legacy interrupt API. Do not include this in your driver or 
 * application source files, use "sys/alt_irq.h" instead to access the proper
 * public API.
 */
 
//#include <errno.h>
#include <system.h>

#ifndef NIOS2_EIC_PRESENT

#include <nios2.h>
//#include <alt_types.h>
#include <sync.h>

//#include <alt_irq.h>

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */


/*
 * alt_irq_disable() disables the individual interrupt indicated by "id".
 */
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_disable (alt_u32 id)
{
  	int intr_flag;
	local_intr_save (intr_flag);
    {
        alt_u32 alt_irq_active;
        NIOS2_READ_IENABLE (alt_irq_active);
        alt_irq_active &= ~(1 << id);
        NIOS2_WRITE_IENABLE (alt_irq_active);
    }
    local_intr_restore(intr_flag)
    return 0;
}

/*
 * alt_irq_enable() enables the individual interrupt indicated by "id".
 */
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_enable (alt_u32 id)
{
    int intr_flag;
    local_intr_save (intr_flag);
    {
        NIOS2_READ_IENABLE (alt_irq_active);
        alt_irq_active |= (1 << id);
        NIOS2_WRITE_IENABLE (alt_irq_active);
    }
    local_intr_restore(intr_flag);
    return 0;
}



#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* NIOS2_EIC_PRESENT */

#endif /* __ALT_LEGACY_IRQ_H__ */
